using System.Collections;
using UnityEngine;

public class SlowMotionManager : MonoBehaviour
{
	public static SlowMotionManager Instance;

	private int countSlowOnHitLate;

	private int countSlowOnHit;

	private bool slowOnHit;

	public float realtimeCDOnHit;

	public float timeSacleOnHit;

	public float timeScale;

	private void Start()
	{
		Instance = this;
	}

	public void _SlowOnHit()
	{
		countSlowOnHit++;
		if (!slowOnHit)
		{
			countSlowOnHitLate = countSlowOnHit;
			slowOnHit = true;
			StartCoroutine(delay_SlowOnHit(realtimeCDOnHit));
		}
	}

	private IEnumerator delay_SlowOnHit(float time)
	{
		yield return new WaitForSecondsRealtime(time);
		if (countSlowOnHitLate == countSlowOnHit)
		{
			countSlowOnHit = 0;
			countSlowOnHitLate = 0;
			slowOnHit = false;
		}
		else
		{
			countSlowOnHitLate = countSlowOnHit;
			StartCoroutine(delay_SlowOnHit(realtimeCDOnHit));
		}
	}

	private void Update()
	{
		if (!BadLogic.pause)
		{
			if (slowOnHit)
			{
				Time.timeScale = timeSacleOnHit;
			}
			else
			{
				Time.timeScale = timeScale;
			}
			Time.fixedDeltaTime = 0.02f * Time.timeScale;
		}
	}
}
